package com.ruiysoft.service.wechat.redis.impl;

import com.ruiysoft.entity.wechat.WXConstant;
import com.ruiysoft.service.wechat.redis.IRedisWeChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * Created by 化增光 on 2018/11/3.
 */
@Service
public class RedisWeChatServiceImpl implements IRedisWeChatService {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    @Override
    public void saveAccessToken(String appId, int second, String access_token) {
        this.redisTemplate.opsForValue().set(WXConstant.REDIS_KEY_ACCESS_TOKEN+appId, access_token);
        this.redisTemplate.expire(WXConstant.REDIS_KEY_ACCESS_TOKEN+appId, second, TimeUnit.SECONDS);

    }

    @Override
    public String getAccessToken(String appId) {
        return redisTemplate.opsForValue().get(WXConstant.REDIS_KEY_ACCESS_TOKEN+appId);
    }
}
